
<template>
    <!-- <div class="title-box-comp" :class="{'title-h1-box': type == 1}"> -->
    <div class="pres-basic-comp">
        <div class="title-box">
            <TitleBox>
                <template #titlecont>
                    <span class="label-link-txt" v-lang="{lang: controlSto.language, lgid: -114}">Prescription information</span>
                    <!-- <span v-lang="{lang: controlSto.language, lgid: -24}">Information</span> -->
                </template>
            </TitleBox>
        </div>

        

        <div class="condition-box">
            <div class="condition-left"></div>
            <div class="condition-right">
                <!-- <div class="ipt-cont">
                    <el-input class="ipt-search" v-model="condObj.searchword" autofocus :placeholder="searchPlace" />
                </div>
                <SearchBtn class="search-item" @click.stop="toSearch"/> -->
                <SearchLoad type='prescriptionDetailBasic' :uiCode="condObj.uiCode" :para="{'content': '', 'langCode': controlSto.language == 1 ? 'ENG' : 'CHN', 'pxId': detailId, 'uiTypeCode': condObj.uiCode}" />
            </div>
        </div>



        <div class="info-cont-box">
            <DetailItemList :data="dataObj.dataList"></DetailItemList>
            
            <!-- <div class="page-box">
                <uiPagination
                    :total="condObj.total" :pageSize="condObj.pageSize" :pageIndex="condObj.pageIndex"
                    @onSizeChange="chgSize" @onCurrentChange="chgCurrnt"/>
            </div> -->
        </div>
    </div>
</template>

<script setup>
    import { ref, reactive, toRefs, onBeforeMount, computed, watch } from 'vue'
    import TitleBox from '@/components/TitleBox.vue'
    import SearchBtn from '@/components/SearchBtn.vue'
    import SearchLoad from '@/components/SearchLoad.vue'
    import uiPagination from '@/components/ui-pagination.vue'
    import { langTxt } from '@/utils/util'
    import { controlStore } from '@/stores/control'
    import { debounce } from 'lodash'

    import { getPrescriptionBasic, downPrescriptionBasic } from '@/service/tcm'

    const emitter = defineEmits(['toCalc']);
    const props = defineProps({
        detailId: {
            type: [Number, String],
            default: ''
        }
    });
    const { detailId } = toRefs(props);


    let searchDebounce = null;

	const controlSto = controlStore();
    const isLoading = ref(true);

    const condObj = reactive({
		searchword: '',
        word: '',
		filterKey: 'pres1',
        uiCode: 'prescription_basic_info',
        total: 0,
        pageSize: 10,
        pageIndex: 1
	});
	const dataObj = reactive({
		dataList: []
	});

    onBeforeMount(()=> {
        initDebounce();
        toGetData();
    });

    const searchPlace = computed(() => {
		return langTxt(controlSto.language, '-15');
	});

    const initDebounce = () => {
        searchDebounce = debounce((e) => {
           getDataList(e);
        }, 400);
    };

    const toLoad = (t) => {
        console.log(detailId.value)
        const param = {
            content: '',
            exportType: t,
            langCode: controlSto.language == 1 ? 'ENG' : 'CHN',
            pxId: detailId.value,
            uiTypeCode: 'prescription_basic_info'
        }
        downPrescriptionBasic(param).then(res => {
            console.log(res, '===')
        })
    }
    const toGetData = () => {
        searchDebounce && searchDebounce();
    };
    const getDataList = () => {
        let params = {
            langCode: controlSto.language == 1 ? 'ENG' : 'CHN',
            prescriptionId: detailId.value,
            content: condObj.word,
            uiTypeCode: condObj.uiCode,
			// pageNo: condObj.pageIndex || 10,
			// pageSize: condObj.pageSize || 1
        };
        isLoading.value = true;
        getPrescriptionBasic(params).then((res) => {
            isLoading.value = false;
            if (res.success && res.data) {
                dataObj.dataList = res.data || [];
            }
        }).catch(() => {
            isLoading.value = false;
        });

        emitter('toCalc');
    };

    const chgSize = (e) => {
        condObj.pageSize = e || 10;
        toGetData();
    };
    const chgCurrnt = (e) => {
        condObj.pageIndex = e || 1;
        toGetData();
    };

    const toSearch = () => {
        condObj.word = condObj.searchword;
        condObj.pageIndex = 1;
        toGetData();
    };

    watch(() => controlSto.language, (n, v) => {
        if(n != v && v) {
            toGetData();
        }
    }, { immediate: true });

    
</script>


<style lang="scss" scoped>
    .pres-basic-comp {
        .condition-box {
            display: flex;
            padding: 32px 0 0;
            justify-content: space-between;
            position: relative;;
            .condition-right {
                position: absolute;
                right:0;
                top: -45px;
                .ipt-cont {
                    display: inline-block;
                    padding-right: 16px;
                    .ipt-search {
                        // width: 300px;
                    }
                }
                .search-item {
                    margin-right: 16px;
                }
            }
        }
        .page-box {
            padding: 10px 0;
        }
    }
</style>
